package mo.leetcode_top;

import mo.common.TreeNode;

public class L108 {

    public TreeNode sortedArrayToBST(int[] nums) {
        return build(nums, 0, nums.length - 1);
    }

    private TreeNode build(int[] nums, int start, int end) {
        if (start > end) {
            return null;
        }
        int mid = start + (end - start) / 2;
        TreeNode root = new TreeNode(nums[mid]);
        root.left = build(nums, start, mid-1);
        root.right = build(nums, mid+1, end);
        return root;
    }

    public static void main(String[] args) {
        L108 test = new L108();
        TreeNode treeNode = test.sortedArrayToBST(new int[]{-10,-3,0,5,9});
        System.out.println(treeNode);
    }
}
